package com.gerald.shop.controller;


import com.gerald.shop.common.utils.PageUtils;
import com.gerald.shop.common.utils.R;
import com.gerald.shop.entity.GoodsEntity;
import com.gerald.shop.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author gerald
 * @email sun@gmail.com
 * @date 2022-01-03 17:43:51
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    @GetMapping("/list")
    public List<GoodsEntity> list() {
        return goodsService.list();
    }

    /**
     * 列表
     */
    @RequestMapping("/page")
    public PageUtils page(@RequestParam Map<String, Object> params) {
        return goodsService.queryPage(params);
    }
//    @RequestMapping("/list")
//    public R list(){
//        return R.ok().put("list", goodsService.list());
//    }
//    /**
//     * 列表
//     */
//    @RequestMapping("/page")
//    public R list(@RequestParam Map<String, Object> params){
//        PageUtils page = goodsService.queryPage(params);
//
//        return R.ok().put("page", page);
//    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public GoodsEntity info(@PathVariable("id") Long id) {
        return goodsService.getById(id);


    }

    /**
     * 保存 添加
     */
    @RequestMapping("/save")
    public boolean save(@RequestBody GoodsEntity goods) {
//        goods.setGupTime(new Date());
        return goodsService.save(goods);

    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public boolean update(@RequestBody GoodsEntity goods) {
        return goodsService.updateById(goods);
    }


    /**
     * 删除
     */
    @RequestMapping("/delete")
    public boolean delete(@RequestBody Long[] ids) {
        return goodsService.removeByIds(Arrays.asList(ids));

    }

}
